package com.tutorial.graphics;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class GraphicsTest extends JFrame{
	
	public GraphicsTest(){
		init();
		this.setVisible(true);
	}
	
	public void init(){
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setBounds(0, 0, 400, 400);
		Container pane = this.getContentPane();
		
		MyPanel panel = new MyPanel();
		pane.add(panel,BorderLayout.CENTER);
		
	}
	
	public static void main(String[] args) {
		new GraphicsTest();
	}
}

class MyPanel extends JPanel{
	
	@Override
	public void paintComponent(Graphics g) {
		super.paintComponents(g);
		g.setColor(Color.black);
		g.drawLine(10,10, 50, 50);
		
		g.drawRect(70, 10, 60, 30);
		
		g.draw3DRect(60, 60, 100, 50, false);
		
		g.setColor(Color.GREEN);
		g.fill3DRect(165, 60, 100, 50, true);
		g.fillRect(275, 60, 100, 50);
		g.clearRect(290, 70, 20, 10);
		
		g.drawRoundRect(10, 115, 100, 50, 15, 15);//x y width height arcW arcH
		g.fillRoundRect(115, 115, 100, 50, 15, 15);
		
		
		g.drawOval(220, 115, 100, 50);
		g.setColor(Color.black);
		g.drawArc(10, 170, 100, 50, 0, 60);
		g.fillArc(70, 170, 100, 100, 0, 60);
		
		
		int xs[] = new int[]{270,220,320,270};
		int ys[] = new int[]{170,230,230,170};
		g.drawPolygon(xs, ys, 4);
		
		g.clipRect(10, 240, 100, 50);
		g.drawRect(60, 265, 100, 50);
//		g.drawRect(60, 265, 50, 25);
//		
		g.setClip(0, 0, this.getWidth(), this.getHeight());
//		g.copyArea(int x,int y,int width,int height, int dx, int dy);
		g.copyArea(165, 60, 80, 40, 50, 110);
		
//		repaint();
		
	}
}
